home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 May / com_0505_1.iso / opensource / top10 / amc_install.exe / {app} / Scripts / Cinema - PTGate (imagem grande).ifs < prev    next >
Encoding:
Text File  |  2004-06-07  |  14.9 KB  |  497 lines

  1. // GETINFO SCRIPTING
  2. // http://cinema.ptgate.pt/(imagem grande)
  3. // Script feito pelo O Guardiπo versπo 1.0 Alpha 2
  4. // 29-05-2004
  5.  
  6.  
  7. (***************************************************
  8.  *  For use with Ant Movie Catalog 3.4.0           *
  9.  *  www.antp.be/software/moviecatalog              *
  10.  *                                                 *
  11.  *  The source code of the script can be used in   *
  12.  *  another program only if full credits to        *
  13.  *  script author and a link to Ant Movie Catalog  *
  14.  *  website are given in the About box or in       *
  15.  *  the documentation of the program               *
  16.  *                                                 *
  17.  *  Please dont remove credits                     *
  18.  *  Reportem os erros para bruno_mga@hotmail.com   *
  19.  ***************************************************)
  20. program PTGate;
  21. const
  22.   BaseAddress = 'http://cinema.ptgate.pt/';
  23.   ManualPictureSelect = True;
  24.   ExternalPictures = False;
  25.   DescriptionToImport = 2;
  26. var
  27.   MovieName: string;
  28.   MovieURL: string;
  29. function HTMLRemove(Value: String): String;
  30. begin
  31.   HTMLDecode(Value);
  32.   HTMLRemoveTags(Value);
  33.   Value := Trim(Value);
  34.   result := Value;
  35. end;
  36.  
  37. procedure AnalyzeFilmPage(Address: String);
  38. var
  39.   Page : TStringList;
  40.   Line, Value : string;
  41.   LineNr, BeginPos, EndPos: Integer;
  42.   AllTitles: TStringList;
  43.   url_imdb:string;
  44. begin
  45.   Page := TStringList.Create;
  46.   Address:='http://cinema.ptgate.pt/filme.php?code='+Address;
  47.   Page.Text := GetPage(Address);
  48.   SetField(fieldURL, Address);
  49.  
  50.  
  51.  
  52.   //obter nome do filme
  53.   LineNr := FindLine('<td bgcolor=#6496D2 width=360 colspan=2><table border=0 cellspacing=0 cellpadding=0><td width=5><br></td><td><font color=white><b class=ttl>', Page, 0);
  54.   if LineNr<>-1 then
  55.   begin
  56.     Value := Page.GetString(LineNr+1);
  57.     BeginPos := pos('</b><br><', value)+9;
  58.     value:=copy(value,4,BeginPos);
  59.  
  60.    AllTitles := TStringList.Create;
  61.    AllTitles.Add(HTMLRemove(value));
  62.  
  63.     //por o the no principio do nome
  64.     if pos(', The</b><br>',value) <>0 then
  65.     begin
  66.       url_imdb:=HTMLRemove(value);
  67.       value:= StringReplace(value, ', The</b><br>', '');
  68.       value:='The '+value;
  69.       value:=HTMLRemove(value);
  70.       AllTitles.Add(value);
  71.     end;
  72.  
  73.     value:=HTMLRemove(value);
  74.     SetField(fieldOriginalTitle, Value);
  75.   end;
  76.   
  77.   //imagem
  78.   Value := Page.GetString(LineNr-1);
  79.   Value:= StringReplace(value, '            "></td>', '');
  80.   Value:= StringReplace(value, '            ', '');
  81.   Value:='http://cinema.ptgate.pt/'+value;
  82.   GetPicture(Value, False);
  83.  
  84.   //obter nome traduzido
  85.   Value := Page.GetString(LineNr+1);
  86.   BeginPos := pos('><i class=subttl>', value)+17;
  87.   EndPos:=Pos('<br></i></td><td width=5><br></',value);
  88.   value:=copy(value,BeginPos,EndPos-BeginPos);
  89.   value:=Copy(value,1,endpos);
  90.   value:=HTMLRemove(value);
  91.   SetField(fieldTranslatedTitle, Value);
  92.  
  93.  
  94.   //Realizador
  95.   LineNr := FindLine('<!-- real -->', Page, 0);
  96.   if LineNr<>-1 then
  97.   begin
  98.     Value := Page.GetString(LineNr+3);
  99.     BeginPos:=Pos('>',value)+1;
  100.     EndPos:=Pos('</a>',value);
  101.     value:=copy(value,BeginPos,EndPos-BeginPos);
  102.     value:=HTMLRemove(value);
  103.     SetField(fieldDirector, Value);
  104.   end;
  105.  
  106.   //actores
  107.   LineNr := FindLine('><b>IntΘrpretes: </b>', Page, 0);
  108.   if LineNr<>-1 then
  109.   begin
  110.     Value := Page.GetString(LineNr+1);
  111.     value:= StringReplace(value,'            </font></td>' , '');
  112.     value:= StringReplace(value,'            ' , '');
  113.     value:=HTMLRemove(value);
  114.     SetField(fieldActors, Value);
  115.   end;
  116.  
  117.   //ano
  118.   LineNr := FindLine('<!-- ano -->', Page, 0);
  119.   if LineNr<>-1 then
  120.   begin
  121.     Value := Page.GetString(LineNr+1);
  122.     value:=HTMLRemove(value);
  123.     BeginPos:=pos('Ano:',value);
  124.     Value:=Copy(value,beginPos+6,length(value));
  125.     SetField(fieldYear, value);
  126.   end;
  127.   url_imdb:=url_imdb+' ('+Value+')';
  128.   
  129.   //genero
  130.   LineNr := FindLine('<!-- gene -->', Page, 0);
  131.   if LineNr<>-1 then
  132.   begin
  133.     Value := Page.GetString(LineNr+1);
  134.     BeginPos:=Pos('<font size=2 face=verdana,arial>',Value);
  135.     EndPos:=Pos('</font></td>',Value);
  136.     value:=Copy(value,BeginPos,EndPos-BeginPos);
  137.     value:=HTMLRemove(value);
  138.     SetField(fieldCategory, value);
  139.   end;
  140.  
  141.   //paφs
  142.   LineNr := FindLine('<!-- pais -->', Page, 0);
  143.   if LineNr<>-1 then
  144.   begin
  145.     Value:= Page.GetString(LineNr+1);
  146.     BeginPos:=Pos('<font size=2 face=verdana,arial>',Value);
  147.     EndPos:=Pos('</font></td>',Value);
  148.     value:=Copy(value,BeginPos,EndPos-BeginPos);
  149.     value:=HTMLRemove(value);
  150.    SetField(fieldCountry, value);
  151.   end;
  152.  
  153.   //descriτπo
  154.   LineNr := FindLine('<!-- wall -->', Page, 0);
  155.   Value:= Page.GetString(LineNr+1);
  156.   if (LineNr<>-1) and (pos('<b>Sinopse</b><br>',value)<>0)  then
  157.   begin
  158.     Value:= Page.GetString(LineNr+2);
  159.     EndPos:=Pos('<br><br></font>',value);
  160.     Value:=Copy(Value,1,EndPos);
  161.     Value:=HTMLRemove(value);
  162.     SetField(fieldDescription, value);
  163.   end;
  164.  
  165.   url_imdb:=AllTitles.GetString(0)+' '+url_imdb;
  166.   
  167.   //imdb
  168.   url_imdb:= StringReplace(url_imdb, ' ', '+');
  169.   url_imdb:='http://us.imdb.com/Title?'+url_imdb;
  170.   Page.Text := GetPage(url_imdb);
  171.  
  172.   // Length
  173.   LineNr := FindLine('Runtime:', Page, 0);
  174.   if LineNr > -1 then
  175.   begin
  176.     Line := Page.GetString(LineNr + 1);
  177.     EndPos := pos(' min', Line);
  178.     if EndPos = 0 then
  179.       EndPos := pos('  /', Line);
  180.     if EndPos = 0 then
  181.       EndPos := Length(Line);
  182.     if Pos(':', Line) < EndPos then
  183.       BeginPos := Pos(':', Line) + 1
  184.     else
  185.       BeginPos := 1;
  186.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  187.     SetField(fieldLength, Value);
  188.   end;
  189.   
  190.     // Rating
  191.   LineNr := FindLine('User Rating:', Page, 0);
  192.   if LineNr > -1 then
  193.   begin
  194.     Line := Page.GetString(LineNr + 4);
  195.     if Pos('/10', Line) > 0 then
  196.     begin
  197.       BeginPos := pos('<b>', Line) + 3;
  198.       Value := IntToStr(Round(StrToInt(StrGet(Line, BeginPos), 0) + (StrToInt(StrGet(Line, BeginPos + 2), 0) / 10)));
  199.       SetField(fieldRating, Value);
  200.     end;
  201.   end;
  202.  
  203.  
  204.   AllTitles.Add(Getfield(fieldOriginalTitle));
  205.   GetMoviePicture('English', Page, AllTitles);
  206.   AllTitles.Free;
  207.   
  208. end;
  209.  
  210. procedure GetMoviePicture(Language: string; Page, AllTitles: TStringList);//copiado do IMDB (large Pic)
  211. var
  212.   Line, Value, Value2, Aka, PictureAddress: string;
  213.   AmazonPage: TStringList;
  214.   FoundOnAmazon, PickTreeSelected, PictureAvailable: Boolean;
  215.   TitleRef, ImgRef, NoImage: string;
  216.   LineNr, BeginPos, EndPos, PickTreeCount, ParagraphIndex, Index, TitleLine, LastMatch: Integer;
  217. begin
  218.   FoundOnAmazon := False;
  219.  
  220.   // Find Alternate Titles for Movies which are not in English
  221.   Aka := '';
  222.   if Language <> 'English' Then
  223.   begin
  224.     LineNr:= FindLine('Also Known As',Page,0);
  225.     EndPos:=0;
  226.     if LineNr > -1 then
  227.     begin
  228.       Line := Page.GetString(LineNr);
  229.       repeat
  230.         Aka:=FindValue('<br>','<br>',Page,LineNr,Line);
  231.         if Aka <> '' then
  232.         begin
  233.           BeginPos:=1;
  234.           EndPos:=Pos('(',Line);
  235.           if EndPos = 0 then
  236.             EndPos := Length(Aka);
  237.           Value := copy(Aka, BeginPos, EndPos - BeginPos - 1);
  238.           Value:=TransFormIMDBTitle(Value);
  239.           AllTitles.Add(Value);
  240.         end;
  241.       until (Pos('Runtime',Line) > 0) or (Pos('MPAA',Line) > 0 ) or (Pos('Country', Line) > 0) or (Pos('Certification', Line) > 0);
  242.     end;
  243.   end;
  244.  
  245.   TitleRef:='dvd>';
  246.   ImgRef:='dvd><img';
  247.   NoImage:='/icons/dvd-no-image.gif';
  248.   LineNr := FindLine('title="DVD available at Amazon.com"', Page, 0);
  249.   if LineNr = -1 then
  250.   begin
  251.     LineNr := FindLine('title="VHS available at Amazon.com"', Page, 0);
  252.     if LineNr > -1 then
  253.     begin
  254.       TitleRef:='video>';
  255.       ImgRef:='video><img';
  256.       NoImage:='/icons/video-no-image.gif';
  257.     end;
  258.   end;
  259.  
  260.   if LineNr > -1 then
  261.   begin
  262.     Line := Page.GetString(LineNr);
  263.     if(TitleRef='dvd>') then
  264.     begin
  265.       EndPos := pos('title="DVD', Line);
  266.       BeginPos := pos('title="VHS', Line);
  267.       while (BeginPos > 0) and (BeginPos<EndPos) do
  268.       begin
  269.         Delete(Line, 1, BeginPos+1);
  270.         BeginPos := pos('title="VHS', Line);
  271.       end;
  272.     end;
  273.     BeginPos := Pos('href="', Line) + 5;
  274.     Delete(Line, 1, BeginPos);
  275.     EndPos := Pos('"', Line);
  276.     Value := Copy(Line, 1, EndPos - 1);
  277.     AmazonPage := TStringList.Create;
  278.     AmazonPage.Text := GetPage('http://us.imdb.com' + Value);
  279.  
  280.     // Original Title
  281.     Value2 := AllTitles.GetString(0);
  282. //    Value2 := TransFormIMDBTitle(Value2);
  283.  
  284.     PickTreeClear;
  285.     PickTreeCount := 0;
  286.     PickTreeAdd('Available Titles for matching a picture to: ' + Value2, '');
  287.  
  288.     ParagraphIndex := 1;
  289.     LineNr := 0;
  290.     LastMatch := -1;
  291.     TitleLine := -1;
  292.     repeat
  293.       LineNr := FindLine('<b>'+IntToStr(ParagraphIndex)+'.', AmazonPage, LineNr);
  294.  
  295.       if LineNr > -1 then
  296.       begin
  297.         TitleLine:=LineNr;
  298.         Value:='';
  299.         PictureAvailable:=False;
  300.         repeat
  301.           TitleLine:=TitleLine +1;
  302.           Line:= AmazonPage.GetString(TitleLine);
  303.           BeginPos:=0;
  304.           if Pos(TitleRef,Line) > 0 then
  305.           begin
  306.             if Pos(ImgRef,Line) = 0 then
  307.             begin
  308.               for Index:=0 to AllTitles.Count -1 do
  309.               begin
  310.                 Value2:=AllTitles.GetString(Index);
  311.                 BeginPos:=Pos(Value2,Line);
  312.                 if BeginPos > 0 then
  313.                   Break;
  314.               end;
  315.               // Match not found
  316.               if BeginPos = 0 then
  317.               begin
  318.                 BeginPos:=Pos(TitleRef,Line)+Length(TitleRef);
  319.                 EndPos:=Pos('</a>',Line);
  320.                 Value:=Copy(Line,BeginPos,EndPos-BeginPos);
  321.               end;
  322.             end
  323.             else
  324.             begin
  325.               PictureAvailable:=(Pos(NoImage,Line) = 0);
  326.               PictureAddress:=IntToStr(TitleLine);
  327.             end;
  328.           end;
  329.           if BeginPos > 0 then
  330.             Break;
  331.         until (Pos('</table>',Line ) > 0);
  332.  
  333.         // Try to Find a Title Match
  334.         if Pos(Value2,Line) > 0 then
  335.         begin
  336.           // Compare Current Title to Original
  337.           BeginPos := Pos(TitleRef, Line) + Length(TitleRef) -1;
  338.           Delete(Line, 1, BeginPos);
  339.           EndPos:= Pos('(',Line);
  340.           if EndPos = 0 Then
  341.             EndPos := Pos('</a>', Line);
  342.           Value := Copy(Line, 1, EndPos - 1);
  343.           Value:= Trim(Value);
  344.           if Value = Value2 then
  345.           begin
  346.             if PictureAvailable then
  347.               LastMatch:=LineNr;
  348.               //Break
  349.           end;
  350.         end;
  351.         if PictureAvailable then
  352.         begin
  353.           PickTreeAdd(Value,PictureAddress);
  354.           PickTreeCount:=PickTreeCount+1;
  355.         end;
  356.       end;
  357.       ParagraphIndex:=ParagraphIndex+1;
  358.     until (LineNr = -1);
  359.     LineNr:=LastMatch;
  360.     if (LineNr = -1) then
  361.     begin
  362.       // Handle Amazon Page Redirection(s)
  363.       LineNr:= FindLine('You clicked on this item',AmazonPage,0);
  364.       if (LineNr = -1) then
  365.         LineNr:=FindLine('Customers who bought',AmazonPage,0);
  366.       // Display the Picture Selection Window
  367.       if (LineNr = -1) and ManualPictureSelect and (PickTreeCount > 0) then
  368.       begin
  369.         PickTreeSelected:=PickTreeExec(PictureAddress);
  370.         if PickTreeSelected then
  371.           LineNr:=StrToInt(PictureAddress,0);
  372.       end;
  373.       if (LineNr > -1 ) then
  374.       begin
  375.         LineNr := FindLine('src="http://images.amazon.com/images/P/',AmazonPage, LineNr);
  376.         if not PickTreeSelected then
  377.           TitleLine:= FindLine('/exec/obidos/ASIN/',AmazonPage, 0);
  378.         if (LineNr > TitleLine) then
  379.           LineNr:=-1;
  380.         if LineNr > -1 then
  381.         begin
  382.           Line := AmazonPage.GetString(LineNr);
  383.           BeginPos := Pos('src="http://images.amazon.com/images/P/', Line) + 4;
  384.           Delete(Line, 1, BeginPos);
  385.           EndPos := Pos('"', Line);
  386.           Value := Copy(Line, 1, EndPos - 1);
  387.           Value := StringReplace(Value, 'TZZZZZZZ', 'LZZZZZZZ');
  388.           Value := StringReplace(Value, 'THUMBZZZ', 'LZZZZZZZ');
  389.           GetPicture(Value, ExternalPictures);
  390.           FoundOnAmazon := True;
  391.         end;
  392.       end;
  393.     end
  394.     else
  395.     begin
  396.       LineNr := FindLine('http://images.amazon.com/images/P/', AmazonPage, LineNr);
  397.       if LineNr < TitleLine then
  398.       begin
  399.         Line := AmazonPage.GetString(LineNr);
  400.         BeginPos := Pos('src="', Line) + 4;
  401.         Delete(Line, 1, BeginPos);
  402.         EndPos := Pos('"', Line);
  403.         Value := Copy(Line, 1, EndPos - 1);
  404.         Value := StringReplace(Value, 'THUMBZZZ', 'LZZZZZZZ');
  405.         GetPicture(Value, ExternalPictures);
  406.         FoundOnAmazon := True;
  407.       end;
  408.     end;
  409.     AmazonPage.Free;
  410.   end;
  411.  
  412.   if not FoundOnAmazon then
  413.   begin
  414.     {  not found on Amazon, so taking what's available directly on IMDB.
  415.        if we are lucky, a picture from amazon but directly linked in the page  }
  416.     LineNr := FindLine('<img border="0" alt="cover"', Page, 0);
  417.     if LineNr > -1 then
  418.     begin
  419.       Line := Page.GetString(LineNr);
  420.       BeginPos := pos('src="', Line) + 4;
  421.       Delete(Line, 1, BeginPos);
  422.       EndPos := pos('"', Line);
  423.       Value := copy(Line, 1, EndPos - 1);
  424.       GetPicture(Value, ExternalPictures);
  425.     end;
  426.   end;
  427. end;
  428.  
  429.  
  430.  
  431.  
  432. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  433. var
  434.   i: Integer;
  435. begin
  436.   result := -1;
  437.   if StartAt < 0 then
  438.     StartAt := 0;
  439.   for i := StartAt to List.Count-1 do
  440.     if Pos(Pattern, List.GetString(i)) <> 0 then
  441.     begin
  442.       result := i;
  443.       Break;
  444.     end;
  445. end;
  446.  
  447. procedure AnalyzePage(Address: string);
  448. var
  449.   Page: TStringList;
  450.   LineNr, StartPos, EndPos: Integer;
  451.   Line: string;
  452.   x:integer;
  453.   MovieAddress, findMovieName,linedown : string;
  454.   guardar,url, nome_filme:string;
  455. begin
  456.   PickTreeClear;
  457.   Page := TStringList.Create;
  458.   Page.Text := GetPage(Address);
  459.  
  460.   if (pos('Nπo foram encontrados filmes ou pessoas que satisfaτam a sua pesquisa.', Page.Text)<>-1) then   //se existe
  461.   begin
  462.       LineNr := FindLine('filme.php?code=', Page, LineNr);
  463.       Line := Page.GetString(LineNr);
  464.     repeat
  465.         StartPos := pos('filme.php?code=', Line)+15;
  466.         if StartPos=15 then break;
  467.  
  468.         guardar:=Copy(line,StartPos+1,9999);
  469.         line:=Copy(line,StartPos,9999);    
  470.         StartPos := pos('>',line)+1;
  471.         url:=(copy(line,1,StartPos-3));
  472.         EndPos := pos('</a>',line)-1;
  473.         line := copy(Line, StartPos, EndPos - StartPos+1);
  474.           nome_filme:=line;
  475.         PickTreeAdd(nome_filme, url);
  476.         line:=guardar;
  477.         
  478. until (nome_filme='');
  479.  
  480.     if PickTreeExec(Address) then begin
  481.       AnalyzeFilmPage(Address);
  482.     end;
  483.     Page.Free;
  484.   end;
  485.   DisplayResults;
  486. end;
  487. begin
  488.   PickListClear;
  489.   MovieName := GetField(fieldOriginalTitle);
  490.   if Input('Importar do cinema.ptgate.pt', 'Escreva o nome do filme:', MovieName) then begin
  491.   //espaτo nπo sπo permitidos
  492.   MovieName := StringReplace(MovieName, ' ', '%20');
  493.   AnalyzePage('http://cinema.ptgate.pt/pesquisa.php?tx='+MovieName);
  494.   end;
  495. end.
  496.  
  497.